package net.sapfree.core.filter;
 
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

public class ChangeReqEncoding implements Filter{
	private final static Logger log = Logger.getLogger(ChangeReqEncoding.class.getClass()); 


    protected FilterConfig config;
    protected String encoding;
    
	    public ChangeReqEncoding()
	    {
	    }

	    public void init(FilterConfig filterconfig)
	    {
	        config = filterconfig;
	        encoding = filterconfig.getInitParameter("encoding");
	        log.debug("the default encoding is:"+encoding);
	        if(encoding == null)
	            encoding = "utf-8";
	    }

	    public void doFilter(ServletRequest servletrequest, ServletResponse servletresponse, FilterChain filterchain)
	        throws IOException, ServletException
	    {
	        HttpServletRequest httpservletrequest = (HttpServletRequest)servletrequest;
	        httpservletrequest.setCharacterEncoding(encoding);
	        filterchain.doFilter(servletrequest, servletresponse);
	    }

	    public void destroy()
	    {
	    }
	}
